<?php
namespace app\admin\controller;


use think\Db;

class Cate extends AdminController
{
//    分类列表
    public function CateList()
    {
        $clist = Db::table('zz_cate')->order('zz_cate_id','asc')->paginate(4);
        $total = count(Db::table('zz_cate')->field('zz_cate_id')->select());
        return view('cate/cate-list',['clist'=>$clist,'total'=>$total]);
    }

//    分类编辑
    public function CateEdit($id)
    {
        $cate=Db::table('zz_cate')->where('zz_cate_id',$id)->find();
        return view('cate/cate-edit',['cate'=>$cate]);
    }

//    停用分类
    public function DoDel()
    {
        $id = input('id');
        $status = input('status');

        $data = array();
        if ($status == 1){
            $data['zz_cate_status'] = 2;
        }else{
            $data['zz_cate_status'] = 1;
        }

        Db::table('zz_cate')->where('zz_cate_id',$id)->update($data);


        $info=[];
        $info['status']=1;
        return json($info);
    }
//    执行编辑
    public function DoEdit()
    {
        $id = input('id','','int');
        $name = input('name');
        $data = array();
        $data['zz_cate_name']=$name;

        Db::table('zz_cate')->where('zz_cate_id',$id)->update($data);
        $info=[];
        $info['status']=1;
        return json($info);
    }
//    新增子分类

    public function CateAdd()
    {
        return view('cate/cate-add');
    }

//    执行新增子分类

    public function DoAdd()
    {

        $name = input('name');
        $data = [];
        $data['zz_cate_name']=$name;

        Db::table('zz_cate')->insert($data);
        $info=[];
        $info['status']=1;
        return json($info);
    }


}
